// 获取当前路由：如/EIS/index为EIS：内镜
export const routeType = {
  mounted () {
    var reg = /\/([^\/]*)\//g
    this.routeType = reg.exec(this.$route.path)[1]
  }
}
// 计算表格高度
export const recalculateTableHeight = {
  mounted () {
    this.recalculateTableHeight()
  },
  methods: {
    recalculateTableHeight () { // 重新计算表格高度
      this.$nextTick(() => {
        var condationHeight = this.$refs.condationHeight.offsetHeight // 条件高度
        var tabHeight = this.$refs.tabHeight.offsetHeight // 表格高度
        var paginationHeight = this.$refs.paginationHeight.offsetHeight // 分页高度
        var clientHeight = document.body.clientHeight // 屏幕高度
        setTimeout(() => {
          this.tableHeight = clientHeight - condationHeight - tabHeight - paginationHeight - 70
        }, 0)
      })
    }
  }
}

// 已知Table区域高度 把table撑开
export const tableContainerHeight = {
  mounted () {
    this.tableContainerHeight()
  },
  methods: {
    tableContainerHeight () { // 重新计算表格高度
      this.$nextTick(() => {
        var tableContainerHeight = this.$refs.tableContainerHeight.offsetHeight
        setTimeout(() => {
          this.tableHeight = tableContainerHeight
        }, 0)
      })
    }
  }
}
// 滚动分页 传参页码，总条数，回调
export const tableAutoScroll = {
  mounted () {
    this.tableAutoScroll()
  },
  methods: {
    tableAutoScroll (PageIndex, TotalPage, callback) {
      // this.$nextTick(() => {
      this.dom = this.$refs.tableAutoScroll.bodyWrapper // 滚动翻页;
      this.dom.addEventListener('scroll', () => {
        // 滚动距离
        var scrollTop = this.dom.scrollTop
        // 变量windowHeight是可视区的高度
        var windowHeight = this.dom.clientHeight || this.dom.clientHeight
        // 变量scrollHeight是滚动条的总高度
        var scrollHeight = this.dom.scrollHeight || this.dom.scrollHeight
        if (scrollTop + windowHeight === scrollHeight) {
          // 获取到的不是全部数据 当滚动到底部 继续获取新的数据
          if ((PageIndex !== TotalPage)) {
            callback()
          }
        }
      })
      // })
    }
  }
}
